#ifndef HYBRIDPLUGINMANAGER_H
#define HYBRIDPLUGINMANAGER_H

#include <QtCore>
#include <QWebPluginFactory>
#include "graphicshybridview.h"
#include "hybridplugininterface.h"

class CoreMethods;
class QLabel;

class DLL_EXPORT HybridPluginManager : public QObject
{
    Q_OBJECT

public:
    HybridPluginManager(GraphicsHybridView *hybridView,QMainWindow *parentWindow, QString identifier);

     /**
      * Return error string if there was an error during plugin loading.
      *
      * @return an error string.
      */
    QString errorString();

public slots:
    /**
     * Load single plugin
     */
    QObject *load(const QString &plugin);

    /**
     *  Call when new frame is created.
     *  @param New frame.
     */
    void initFrame(QWebFrame *frame);

    /**
     * Include plugin's javascript file into given frame.
     */
    void includeJavaScriptFile(const QString &jsFileName, QWebFrame *frame);

	/**
	 * Include a CSS file into given frame.
	 */
	void includeCSSFile(const QString &cssFileName, QWebFrame *frame);

 private slots:
    /**
     *	Called when javascript window object is cleared. We should
     *	initiate new environment in this case. 
     */
    void javaScriptWindowObjectCleared();

	/**
	 * Called when the frame loading is finished.
	 */
	void loadFinished(bool ok);

	/**
	 * Called when javascript window.close() is called.
	 */
	void javaScriptWindowClose();

private:
    GraphicsHybridView *m_hybridView;
    QMainWindow *m_parentWindow;
    QHash<QString, HybridPluginInterface*> m_loadedPlugins;
    QString m_errorString;
    QLabel *m_label;
    QString m_identifier;
};

#endif // HYBRIDPLUGINMANAGER_H
